package com.ruoyi.web.controller.app;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.FyProjectApply;
import com.ruoyi.system.domain.FyProjectApplyAncillary;
import com.ruoyi.system.domain.vo.business.FyProjectApplyAllPassListDto;
import com.ruoyi.system.domain.vo.business.FyProjectApplyDetailVO;
import com.ruoyi.system.domain.vo.business.FyProjectApplySaveVO;
import com.ruoyi.system.domain.vo.business.FyProjectApplySelectListDto;
import com.ruoyi.system.domain.vo.business.FyProjectApplySelectListVO;
import com.ruoyi.system.domain.vo.coopHan.CulvertNoticeDetailVo;
import com.ruoyi.system.domain.vo.coopHan.PageCulvertNoticeVo;
import com.ruoyi.system.dto.coopHan.PageCulvertNoticeDto;
import com.ruoyi.system.service.IFyProjectApplyAncillaryService;
import com.ruoyi.system.service.IFyProjectApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 扶垚计划项目申报Controller
 *
 * @author ruoyi
 * @date 2024-02-28
 */
@Controller
@Api(tags = {"(app)扶垚计划项目申报"})
@RequestMapping("/app/system/fyProjectApply")
public class AppFyProjectApplyController extends BaseController {

    @Autowired
    private IFyProjectApplyService fyProjectApplyService;
    @Autowired
    private IFyProjectApplyAncillaryService ancillaryService;
    /**
     * 查询扶垚计划项目申报列表
     */
    @ApiOperation("查询扶垚计划项目申报列表")
    //@RequiresPermissions("system:application:list")
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult<Page<FyProjectApplySelectListVO>> list(@RequestBody FyProjectApplySelectListDto dto) {
//       这个接口需要返回所有审批通过的数据
//        if (dto.getStatus() != -1) {
//            dto.setApprovalUserId(getUserId());
//        }
        dto.setStatus(1);
        Page<FyProjectApplySelectListVO> list = fyProjectApplyService.pageList(dto);
        return success(list);
    }
    /**
     * 扶垚计划项目所有通过列表
     */
    @ApiOperation("查询扶垚计划项目所有通过列表")
    //@RequiresPermissions("system:application:list")
    @PostMapping("/allPassList")
    @ResponseBody
    public AjaxResult<Page<FyProjectApply>> list(@RequestBody FyProjectApplyAllPassListDto dto) {

        Page<FyProjectApply> list = fyProjectApplyService.allPassList(dto);
        return success(list);
    }


    /**
     * (app)新增保存扶垚计划项目申报
     */
    @ApiOperation("(app)新增扶垚计划项目申报")
    //@RequiresPermissions("system:application:add")
    @Log(title = "(app)扶垚计划项目申报", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(@RequestBody FyProjectApplySaveVO saveVO) {
        try {
            fyProjectApplyService.addOrUpdateSave(saveVO, saveVO.getId());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return success();
    }

    /**
     * (app)修改扶垚计划项目申报
     */
    @ApiOperation("(edit)修改扶垚计划项目申报")
    //@RequiresPermissions("system:application:add")
    @Log(title = "(edit)扶垚计划项目申报", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestBody FyProjectApplySaveVO saveVO) {
        try {
            fyProjectApplyService.addOrUpdateSave(saveVO, null);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return success();
    }

    /**
     * 扶垚计划项目申报详情
     */
    @ApiOperation("扶垚计划项目申报详情")
    //@RequiresPermissions("system:application:edit")
    @GetMapping("/getById/{id}")
    @ResponseBody
    public AjaxResult edit(@PathVariable("id") Long id) {
        FyProjectApplyDetailVO vo = fyProjectApplyService.selectFyProjectApplyDetailVOById(id);
        return success(vo);
    }

    @PostMapping("/pageList")
    @ApiOperation(value = "扶垚计划公示列表")
    @ResponseBody
    public AjaxResult<Page<FyProjectApplySelectListVO>> pageList(@RequestBody PageCulvertNoticeDto dto) {
        Page<FyProjectApplySelectListVO> list = fyProjectApplyService.pageNotice(dto);
        return success(list);
    }

//    @GetMapping("/notice/detail")
//    @ApiOperation(value = "协拍涵公示详情")
//    public AjaxResult<CulvertNoticeDetailVo> noticeDetail(@ApiParam(value = "协拍涵ID", required = true)
//                                                          @RequestParam Long id) {
//        CulvertNoticeDetailVo vo = fyProjectApplyService.noticeDetail(id);
//        return AjaxResult.success(vo);
//    }

    @ApiOperation("扶垚计划公示详情")
    //@RequiresPermissions("system:application:edit")
    @GetMapping("/detail/{id}")
    @ResponseBody
    public AjaxResult detail(@PathVariable("id") Long id) {
        FyProjectApplyDetailVO vo = fyProjectApplyService.selectFyProjectApplyDetailVOById(id);
        return success(vo);
    }

    @ApiOperation("删除扶垚计划项目申报")
    //@RequiresPermissions("system:application:remove")
    @Log(title = "扶垚计划项目申报", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(Long id) {
        ancillaryService.remove(Wrappers.lambdaQuery(FyProjectApplyAncillary.class).
                eq(FyProjectApplyAncillary::getFyProjectApplyId,id));
        return toAjax(fyProjectApplyService.removeById(id));
    }
}
